package com.sky.controller.user;

import com.sky.constant.CacheConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 商店操作接口
 */
@RestController("userShopController")
@RequestMapping("/user/shop")
@Slf4j
@Api(tags = "商店操作接口")
public class ShopController {
    @Autowired
    private RedisTemplate<String,Integer> redisTemplate;
    /**
     * 获取营业状态
     */
    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result<Integer> getStatus(){
        Integer status =redisTemplate.opsForValue().get(CacheConstant.SHOP_STATUS);
        if (status == null) {
            redisTemplate.opsForValue().set(CacheConstant.SHOP_STATUS,0);
            status=0;
        }
        log.info("用户端获取营业状态:{}",status);
        return Result.success(status);
    }
}
